load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library")

go_library(
    name = "go_default_library",
    srcs = ["virt-handler.go"],
    importpath = "kubevirt.io/kubevirt/cmd/virt-handler",
    visibility = ["//visibility:private"],
    deps = [
        "//pkg/certificates/bootstrap:go_default_library",
        "//pkg/container-disk:go_default_library",
        "//pkg/controller:go_default_library",
        "//pkg/healthz:go_default_library",
        "//pkg/inotify-informer:go_default_library",
        "//pkg/monitoring/client/prometheus:go_default_library",
        "//pkg/monitoring/reflector/prometheus:go_default_library",
        "//pkg/monitoring/vms/prometheus:go_default_library",
        "//pkg/monitoring/workqueue/prometheus:go_default_library",
        "//pkg/service:go_default_library",
        "//pkg/util:go_default_library",
        "//pkg/util/webhooks:go_default_library",
        "//pkg/virt-config:go_default_library",
        "//pkg/virt-handler:go_default_library",
        "//pkg/virt-handler/cache:go_default_library",
        "//pkg/virt-handler/cmd-client:go_default_library",
        "//pkg/virt-handler/isolation:go_default_library",
        "//pkg/virt-handler/rest:go_default_library",
        "//pkg/virt-handler/selinux:go_default_library",
        "//pkg/virt-launcher/virtwrap/api:go_default_library",
        "//pkg/watchdog:go_default_library",
        "//staging/src/github.com/golang/glog:go_default_library",
        "//staging/src/kubevirt.io/client-go/api/v1:go_default_library",
        "//staging/src/kubevirt.io/client-go/kubecli:go_default_library",
        "//staging/src/kubevirt.io/client-go/log:go_default_library",
        "//staging/src/kubevirt.io/client-go/util:go_default_library",
        "//vendor/github.com/emicklei/go-restful:go_default_library",
        "//vendor/github.com/spf13/pflag:go_default_library",
        "//vendor/k8s.io/api/core/v1:go_default_library",
        "//vendor/k8s.io/apimachinery/pkg/fields:go_default_library",
        "//vendor/k8s.io/apimachinery/pkg/labels:go_default_library",
        "//vendor/k8s.io/apimachinery/pkg/types:go_default_library",
        "//vendor/k8s.io/client-go/kubernetes/scheme:go_default_library",
        "//vendor/k8s.io/client-go/kubernetes/typed/core/v1:go_default_library",
        "//vendor/k8s.io/client-go/tools/cache:go_default_library",
        "//vendor/k8s.io/client-go/tools/record:go_default_library",
        "//vendor/k8s.io/client-go/util/certificate:go_default_library",
    ],
)

load("//vendor/kubevirt.io/client-go/version:def.bzl", "version_x_defs")

go_binary(
    name = "virt-handler",
    embed = [":go_default_library"],
    visibility = ["//visibility:public"],
    x_defs = version_x_defs(),
)

load(
    "@io_bazel_rules_docker//container:container.bzl",
    "container_image",
)
load("@io_bazel_rules_docker//contrib:group.bzl", "group_entry", "group_file")
load("@io_bazel_rules_docker//contrib:passwd.bzl", "passwd_entry", "passwd_file")
load("@bazel_tools//tools/build_defs/pkg:pkg.bzl", "pkg_tar")

passwd_entry(
    name = "root-user",
    gid = 0,
    home = "/root",
    info = "root",
    shell = "/bin/bash",
    uid = 0,
    username = "root",
)

passwd_entry(
    name = "qemu-user",
    gid = 107,
    home = "",
    shell = "/bin/bash",
    uid = 107,
    username = "qemu",
)

passwd_file(
    name = "passwd",
    entries = [
        ":qemu-user",
        ":root-user",
    ],
)

group_entry(
    name = "qemu-group",
    gid = 107,
    groupname = "qemu",
)

group_entry(
    name = "root-group",
    gid = 0,
    groupname = "qemu",
)

group_file(
    name = "group",
    entries = [
        ":qemu-group",
        ":root-group",
    ],
)

pkg_tar(
    name = "passwd-tar",
    srcs = [
        ":group",
        ":passwd",
    ],
    mode = "0644",
    package_dir = "etc",
    visibility = ["//visibility:public"],
)

container_image(
    name = "version-container",
    directory = "/",
    files = [
        ":virt_launcher.cil",
        "//:get-version",
    ],
    tars = [
        ":passwd-tar",
        "//rpm:launcherbase_x86_64",
    ],
)

container_image(
    name = "virt-handler-image",
    architecture = select({
        "@io_bazel_rules_go//go/platform:linux_ppc64le": "ppc64le",
        "//conditions:default": "amd64",
    }),
    base = ":version-container",
    directory = "/usr/bin/",
    entrypoint = ["/usr/bin/virt-handler"],
    files = [
        ":virt-handler",
        "//cmd/container-disk-v2alpha:container-disk",
        "//cmd/virt-chroot",
    ],
    visibility = ["//visibility:public"],
)
